package com.web.mall.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.web.mall.pojo.*;
import com.web.mall.service.ContentCateManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ContentCateManagerController {

    @Autowired
    private ContentCateManagerService contentCateManagerService;

    @GetMapping("/ContentCategoryListByPage")
    public PageResp<TbContentCategory> listByPage(PageReq pageReq){
        PageHelper.startPage(pageReq.getPage(),pageReq.getSize());
        Page<TbContentCategory> page = (Page<TbContentCategory>) contentCateManagerService.queryContentCategory();

        PageResp pageResp = new PageResp();
        pageResp.setTotal(page.getTotal());
        pageResp.setList(page.getResult());

        return pageResp;
    }

    @DeleteMapping("/deleteContentCategory/{id}")
    public Result deleteContentCategory(@PathVariable Long id){
        boolean b= this.contentCateManagerService.deleteContentCategory(id);
        if (b){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @PostMapping("/saveContentCategory")
    public Result saveContentCategory(@RequestBody TbContentCategory contentCategory){
        System.out.println(contentCategory.getId());
        boolean b= this.contentCateManagerService.saveContentCategory(contentCategory);
        if (b){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @GetMapping("/findContentCategoryList")
    public List<TbContentCategory> findContentCategoryList(){
        return contentCateManagerService.findContentCategoryList();
    }

}
